//
//  FLNViewController.m
//  百思不得姐
//
//  Created by xmg on 16/5/29.
//  Copyright © 2016年 FLN.com. All rights reserved.
//

#import "FLNViewController.h"

#import "UIImage+Image.h"

#import "FLNPublishViewController.h"
#import "FLNNewViewController.h"
#import "FLNMineTableViewController.h"
#import "FLNEssenceViewController.h"
#import "FLNFriendTrendsViewController.h"

#import "FLNTabBar.h"
#import "FLNNavigationController.h"
@interface FLNViewController ()

@end

@implementation FLNViewController

+ (void)load {
    //获取全局的UITabBarItem
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
    //正常状态
    NSMutableDictionary *norAttrTitle = [NSMutableDictionary dictionary];
    norAttrTitle[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [item setTitleTextAttributes:norAttrTitle forState:UIControlStateNormal];
    
    
    //选中状态
    NSMutableDictionary *selAttrTitle = [NSMutableDictionary dictionary];
    selAttrTitle[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    selAttrTitle[NSForegroundColorAttributeName] = [UIColor purpleColor];
    [item setTitleTextAttributes:selAttrTitle forState:UIControlStateSelected];

}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self setupAllViewController];
    
    [self setupAllTabBarButton];
    
    //自定义tabBar
    FLNTabBar *tabBar = [[FLNTabBar alloc] init];
    [self setValue:tabBar forKey:@"tabBar"];
    
}

- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
}

- (void)setupAllTabBarButton {

    //添加子控制器
    //精华
    UIViewController *essenceVc = self.childViewControllers[0];
    essenceVc.tabBarItem.title = @"精华";
    essenceVc.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
    essenceVc.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_essence_click_icon"];
    
    //新帖
    UIViewController *newVc = self.childViewControllers[1];
    newVc.tabBarItem.title = @"新帖";
    newVc.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
    newVc.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_new_click_icon"];
    
    //发布
//    UIViewController *publishVc = self.childViewControllers[2];
//    publishVc.tabBarItem.image = [UIImage imageNamed:@"tabBar_publish_icon"];
//    publishVc.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_publish_click_icon"];
    
    //关注
    UIViewController *friendVc = self.childViewControllers[2];
    friendVc.tabBarItem.title = @"关注";
    friendVc.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"];
    friendVc.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_friendTrends_click_icon"];
    
    
    //我
    UIViewController *mineVc = self.childViewControllers[3];
    mineVc.tabBarItem.title = @"我";
    mineVc.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
    mineVc.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_me_click_icon"];
    
    

}

- (void)setupAllViewController {

    // 添加子控制器
    // 精华
    FLNEssenceViewController *vc = [[FLNEssenceViewController alloc] init];
    // initWithRootViewController:把VC调用push,vc压入栈,导航控制器默认会添加栈顶控制器view
//    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:vc];
    
    // 新帖
    FLNNewViewController *vc1 = [[FLNNewViewController alloc] init];
    // initWithRootViewController:把VC调用push,vc压入栈,导航控制器默认会添加栈顶控制器view
//    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:vc1];
    [self addChildViewController:vc1];
    
//    // 发布
//    FLNPublishViewController *vc2 = [[FLNPublishViewController alloc] init];
//    // initWithRootViewController:把VC调用push,vc压入栈,导航控制器默认会添加栈顶控制器view
//    [self addChildViewController:vc2];
    
    // 关注
    FLNFriendTrendsViewController *vc3 = [[FLNFriendTrendsViewController alloc] init];
    // initWithRootViewController:把VC调用push,vc压入栈,导航控制器默认会添加栈顶控制器view
//    UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:vc3];
    [self addChildViewController:vc3];
    
    // 我
    FLNMineTableViewController *vc4 = [[FLNMineTableViewController alloc] init];
    // initWithRootViewController:把VC调用push,vc压入栈,导航控制器默认会添加栈顶控制器view
//    UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:vc4];
    [self addChildViewController:vc4];

}


- (void)addChildViewController:(UIViewController *)childController {

    FLNNavigationController *nav = [[FLNNavigationController alloc] initWithRootViewController:childController];
    [super addChildViewController:nav];
}

@end
